package sun.superstring.loop;

public class WhileDemo3 {
    public static void main(String[] args) {
        // 目标：认识while循环的写法，搞清楚其执行流程
        test1();
        System.out.println("需要多少年？" + test2() + "年");
        System.out.println("该纸需要折" + test3() + "次，可以折成珠穆朗玛峰的高度8848.86米");
    }
    public static void test1() {
        int i = 0;
        while (i < 3) {
            System.out.println("Hello world!!!");
            i++;
        }
    }
    // 复利的力量
    // 假设你在银行投资了100000元，银行给出的复利是1.7%，问多少年后可以实现本金翻倍
    public static int test2() {
        double money = 100000;
        double rate = 0.017;
        int year = 0;
        while (money < 200000){
            money = money * (1 + rate );
            year++;
//            System.out.println("第" + year + "年，你的钱是" + money);
        }
        return year;
    }

    public static int test3() {
        double montain = 8848860;
        double thick = 0.1;
        int time = 0;
        while(thick < montain){
            thick = thick * 2;
            time++;
        }
        System.out.println("第" + time + "次折，纸的厚度是" + thick);
        return time;
    }
}
